<template>
	<view>
		<!-- 个性签名 -->
		<uni-popup ref="popup" type="bottom">
			<view class="sign_warp">
				<view class="top row_center">
					<view class="cancel" @click="close">
						取消
					</view>
					<view class="title">
						{{title}}
					</view>
					<view class="confirm" @click="confirm">
						保存
					</view>
				</view>
				<view class="uni-textarea" v-if="popType == 5">
					<textarea class="textarea" v-model="newDesc" :cursor-spacing="cursorSpacing" :maxlength="maxlen" placeholder-style="color: #9F9CAE;"
						placeholder="说点什么吧" />
				</view>
				<view class="input_warp" v-if="popType == 4">
					<input type="text" class="nc_input" :cursor-spacing="cursorSpacing" v-model="newDesc" :maxlength="maxlen" placeholder="请输入修改的昵称" />
				</view>
				<view class="bot row_center">
					<view class="left"></view>
					<view class="right"><text style="color: #38D7CF;">{{txtLen}}</text>/{{maxlen}}</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		name: "profile-modify",
		props: {
			cursorSpacing: {
				type: String | Number,
				default: 0
			},
			title: {
				type: String,
				default: '标题'
			},
			popType: {
				type: String | Number,
				default: 4
			},
			desc: {
				type: String,
				default: ''
			},
			maxlen: {
				type: Number,
				default: 15
			}
		},
        watch: {
			newDesc: function(newVal, old) {
				this.txtLen = newVal.length
			}
		},
		data() {
			return {
				txtLen: 0,
				newDesc: ''
			};
		},
		mounted() {
			this.newDesc = this.desc;
		},
		methods: {
			close() {
				this.$refs.popup.close();
			},
			open() {
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open();
				/* this.newDesc = this.desc; */
			},
			confirm() {
				this.$emit('confirm', {
					value: this.newDesc
				})
			}
		}
	}
</script>

<style lang="scss">
	.sign_warp {
		width: 750rpx;
		height: auto;
		padding: 0 85rpx;
		box-sizing: border-box;
		background: #28243D;
		border-top-left-radius: 30rpx;
		border-top-right-radius: 30rpx;

		.top {
			height: 100rpx;
			width: 100%;
			justify-content: space-between;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;

			.cancel {
				color: #F1EDFF;
			}

			.title {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #F1EDFF;
			}

			.confirm {
				color: #3DFFF2;
			}
		}

		.uni-textarea {
			width: 100%;
			height: 160rpx;
			background: rgba(255, 255, 255, 0.05);
			border-radius: 12rpx;

			.textarea {
				padding: 25rpx;
				box-sizing: border-box;
				font-size: 26rpx;
				color: #F1EDFF;
			}
		}

		.input_warp {
			height: 76rpx;
			background: rgba(255, 255, 255, 0.05);
			border-radius: 38rpx;

			.nc_input {
				width: 100%;
				height: 76rpx;
				line-height: 76rpx;
				padding-left: 34rpx;
				font-size: 26rpx;
				color: #F1EDFF;
			}
		}

		.bot {
			height: 78rpx;
			width: 100%;
			color: #F1EDFF;
			justify-content: space-between;
		}
	}
</style>
